package com.powernobug.service.impl;

import com.powernobug.bean.model.MarketAd;
import com.powernobug.bean.model.MarketAdExample;
import com.powernobug.bean.vo.template.AdsTempForHomeIndex;
import com.powernobug.mapper.MarketAdMapper;
import com.powernobug.annotation.PrintThreadLog;
import com.powernobug.service.MarketAdService;
import com.powernobug.util.TransferModelDataUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;

/**
 * @Author: 肖云戈
 * @CreateTime: 2024-08-30
 * @Description:
 */
@Service
public class MarketAdServiceImpl implements MarketAdService {

    @Autowired
    MarketAdMapper marketAdMapper;

    @Override
    @Async("globalThreadPool")
    @PrintThreadLog
    public Future<List<AdsTempForHomeIndex>> getBanners() {
        MarketAdExample example = new MarketAdExample();
        example.createCriteria().andDeletedEqualTo(false);
        example.setOrderByClause("add_time desc");

        List<MarketAd> originData = marketAdMapper.selectByExample(example);
        Class<?> resultType = AdsTempForHomeIndex.class;
        List<AdsTempForHomeIndex> resultData = (List<AdsTempForHomeIndex>) TransferModelDataUtil.transferFatherToSon(resultType, originData);
        return new AsyncResult<>(resultData);
    }
}
